Security News
The Risks of Misguided Research in Supply Chain Security
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
@typeonly/loader
Advanced tools
TypeOnly aims to be the pure typing part of TypeScript. The TypeOnly parser generates a .to.json
file, which is a bundle that contains metadata extracted from .d.ts
typing files. Then, this package provides an API to read these RTO files. It brings typing metadata at runtime.
At first, it is necessary to follow the tutorial of TypeOnly in order to generate a .to.json
file based on your TypeScript definitions. After this step, you have the following file: dist/types.to.json
.
Now, add @typeonly/loader
to the project:
npm install @typeonly/loader
Create a file src/main.js
with the following content:
// src/main.js
const { loadModules, literals } = require("@typeonly/loader");
const modules = loadModules({
bundle: require(`./types.to.json`)
});
const { ColorName } = modules["./drawing"].namedTypes;
console.log("Color names:", literals(ColorName, "string"));
If you write this code in a TypeScript source file, simply replace the require
syntax with a standard import
.
We can execute our program:
$ node src/main.js
Color names: [ 'red', 'green', 'blue' ]
Yes, it’s as easy as it seems: the list of color names is now available at runtime.
Notice: The TypeOnly parser is used at build time. At runtime, our code only use @typeonly/loader
which is a lightweight wrapper for .to.json
files.
With VS Code, our recommanded plugin is:
ms-vscode.vscode-typescript-tslint-plugin
)FAQs
Brings types and interfaces from TypeScript at runtime.
We found that @typeonly/loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Snyk's use of malicious npm packages for research raises ethical concerns, highlighting risks in public deployment, data exfiltration, and unauthorized testing.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.